// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   London.java

package jones.behavior;

import jones.SimpleRobotInterface;

// Referenced classes of package jones.behavior:
//            TimeOut, CountOut, Behavior, Arbiter

public class London
    implements Behavior
{
    private static class State
    {

        private final String name;
        public static final State START = new State("START");
        public static final State WIDTH = new State("WIDTH");
        public static final State RIGHT1 = new State("RIGHT1");
        public static final State HEIGHT = new State("HEIGHT");
        public static final State RIGHT2 = new State("RIGHT2");

        public String toString()
        {
            return name;
        }


        private State(String name)
        {
            this.name = name;
        }
    }


    private static final String NAME = "London";
    private static final double TURN_ANGLE = 90D;
    private static final double MIN_ANGLE = 0.050000000000000003D;
    private static final int FRAMES_PER_SEC = 25;
    private static final int TURN_TIME = 25;
    private static final int TURN_SPEED = 72;
    private double width = 0;
    private double height = 0;
    private TimeOut timeOut = null;
    private CountOut countOut = null;
    private State state = null;

    public London()
    {
        width = 4.2000000000000002D;
        height = 4D;
        timeOut = new TimeOut();
        countOut = new CountOut();
        state = State.START;
    }

    public London(double width, double height)
    {
        this.width = 4.2000000000000002D;
        this.height = 4D;
        timeOut = new TimeOut();
        countOut = new CountOut();
        state = State.START;
        this.width = width;
        this.height = height;
    }

    public String getName()
    {
        return "London";
    }

    public void setWidth(double width)
    {
        this.width = width;
    }

    public double getWidth()
    {
        return width;
    }

    public void setHeight(double height)
    {
        this.height = height;
    }

    public double getHeight()
    {
        return height;
    }

    public void update(double time)
    {
        timeOut.update(time);
        countOut.update(1);
    }

    public void act(Arbiter arbiter)
    {
        SimpleRobotInterface robot = (SimpleRobotInterface)arbiter.getRobotInterface(((Behavior) (this)));
        if (state == State.START)
        {
            timeOut.start();
            state = State.WIDTH;
        } else
        if (state == State.WIDTH)
        {
            robot.setLeftWheelSpeed(robot.getMaxWheelSpeed());
            robot.setRightWheelSpeed(robot.getMaxWheelSpeed());
            if (timeOut.isPast(width))
            {
                countOut.start();
                state = State.RIGHT1;
            }
        } else
        if (state == State.RIGHT1)
        {
            robot.setLeftWheelSpeed(72);
            robot.setRightWheelSpeed(-72);
            if (countOut.isPast(25))
            {
                timeOut.start();
                state = State.HEIGHT;
            }
        } else
        if (state == State.HEIGHT)
        {
            robot.setLeftWheelSpeed(robot.getMaxWheelSpeed());
            robot.setRightWheelSpeed(robot.getMaxWheelSpeed());
            if (timeOut.isPast(height))
            {
                countOut.start();
                state = State.RIGHT2;
            }
        } else
        if (state == State.RIGHT2)
        {
            robot.setLeftWheelSpeed(72);
            robot.setRightWheelSpeed(-72);
            if (countOut.isPast(25))
            {
                timeOut.start();
                state = State.WIDTH;
            }
        }
    }

    public String toString()
    {
        return "London: " + state;
    }
}
